﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    
     <script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
    

    <style type="text/css">
    html, body
    {
        font-size:12px;
        padding:0;
        margin:0;
        border:0;
        height:100%;
        overflow:hidden;
    }
    </style>
</head>
<body>    
    
<fieldset style="border:solid 1px #aaa;padding:3px;">
            <legend >业务数据信息</legend> 
    <form id="form1" method="post">
        <input name="id" class="mini-hidden" />
        <div style="padding-left:11px;padding-bottom:5px;">
            <table style="table-layout:fixed;">
              
<tr>
 <td style="width:12%;text-align:right;" ><span style="color:red;" >*&nbsp;&nbsp;</span>劳动保障证号：</td>
  <td style="width:22%;"><input name="aab999" id="id" style="width:80%;" class="mini-textbox sasLabel" readOnly="readonly" borderStyle="border:0"
  emptyText="请输入单位编号"/>                    </td>
</tr>

<tr>
<td style="width:12%;text-align:right;"><span style="color:red;" >*&nbsp;&nbsp;</span>单位名称：</td>
<td style="width:22%;"><input name="aab004" id="unit_name" style="width:80%;"  vtype="maxLength:100" onvalidation="checkName"  class="mini-textbox" required="true"   /></td>
<td style="width:12%;text-align:right;">单位性质：</td>
<td style="width:22%;"><input name="aab019" style="width:80%;" value="个体工商户" class="mini-textbox sasLabel" borderStyle="border:0"
  allowInput="false"  /></td>
<td style="width:12%;text-align:right;">统一社会信用代码：</td>
<td style="width:22%;"><input name="aab131" style="width:80%;"  class="mini-textbox " 
  id="credit_id" vtype="rangeLength:18,18" maxlength="18" readOnly="readonly"  /></td>
</tr>

<tr>
</tr>
<tr>
<td style="width:12%;text-align:right;">组织机构代码：</td>
<td style="width:22%;"><input name="aab003" style="width:80%;" class="mini-textbox"  id="organization_id" vtype="maxLength:50"  /></td>
<td style="width:12%;text-align:right;">地税登记证号：</td>
<td style="width:22%;"><input name="aab030" style="width:80%;" class="mini-textbox"   vtype="maxLength:40" /></td>
<td style="width:12%;text-align:right;"><span style="color:red;" >*&nbsp;&nbsp;</span>联系人：</td>
<td style="width:22%;"><input name="aae004" style="width:80%;" class="mini-textbox"  vtype="maxLength:50" required="true"  /></td>
</tr>
<tr>
<td style="width:12%;text-align:right;"><span style="color:red;" >*&nbsp;&nbsp;</span>联系电话：</td>
<td style="width:22%;"><input name="aae005" style="width:80%;" class="mini-textbox" required="true"  vtype="int" vtype="maxLength:50" /></td>
<td style="width:12%;text-align:right;white-space:nowrap;"><span style="color:red;" >*&nbsp;&nbsp;</span>法定代表人姓名：</td>
<td style="width:22%;"><input name="aab013" style="width:80%;" class="mini-textbox" required="true" vtype="maxLength:50"  /></td>
<td style="width:12%;text-align:right;white-space:nowrap;"><span style="color:red;" >*&nbsp;&nbsp;</span>法定代表人证件类型：</td>
<td style="width:22%;"><input name="aac058" id="type" style="width:80%;" class="mini-combobox" valueField="bm" textField="mch" 
	url="${pageContext.request.contextPath }/cs_ounit.do?method=getselect&lx=sfzjlx"
 required="true"   emptyText="请输入法定代表人证件类型"/></td>
</tr>
<tr>
<td style="width:12%;text-align:right;white-space:nowrap;"><span style="color:red;white-space:nowrap" >*&nbsp;&nbsp;</span>法定代表人证件号码：</td>
<td style="width:22%;"><input name="aab014" style="width:80%;"  class="mini-textbox"  vtype="maxLength:18" required="true" onvalidation="onNumber"  emptyText="请输入法定代表人证件号码"/></td>
<td style="width:12%;text-align:right;white-space:nowrap;"><span style="color:red;" >*&nbsp;&nbsp;</span>法定代表人联系电话：</td>
<td style="width:22%;"><input name="bae182" style="width:80%;" class="mini-textbox"  vtype="int" vtype="maxLength:50"  emptyText="请输入法定代表人联系电话"/></td>
</tr>

<tr>
<td ><input name="aab078" class="mini-hidden"  /></td>
<td ><input name="aab073" class="mini-hidden"  /></td>
<td ><input name="aab074" class="mini-hidden"  /></td>

<td ><input name="aab156" class="mini-hidden"  /></td>
<td ><input name="aab077" class="mini-hidden"  /></td>
<td ><input name="aab081" class="mini-hidden"  /></td>

<td ><input name="aab082" class="mini-hidden"  /></td>
<td ><input name="aab157" class="mini-hidden"  /></td>
<td ><input name="aae051" class="mini-hidden"  /></td>

<td ><input name="aae048" class="mini-hidden"  /></td>
<td ><input name="aae049" class="mini-hidden"  /></td>
<td ><input name="aaa149" class="mini-hidden"  /></td>

<td ><input name="aac047" class="mini-hidden"  /></td>
<td ><input name="aab006" class="mini-hidden"  /></td>
<td ><input name="aab007" class="mini-hidden"  /></td>

<td ><input name="aab008" class="mini-hidden"  /></td>
<td ><input name="aab009" class="mini-hidden"  /></td>
<td ><input name="aab021" class="mini-hidden"  /></td>

<td ><input name="gmjjhy" class="mini-hidden"  /></td>
<td ><input name="aab202" class="mini-hidden"  /></td>
<td ><input name="aab020" class="mini-hidden"  /></td>

<td ><input name="aab023" class="mini-hidden"  /></td>
<td ><input name="cba001" class="mini-hidden"  /></td>
<td ><input name="aae901" class="mini-hidden"  /></td>

<td ><input name="dwgm" class="mini-hidden"  /></td>
<td ><input name="aae902" class="mini-hidden"  /></td>
<td ><input name="dwzxrq" class="mini-hidden"  /></td>
</tr>


            </table>
        </div>
       
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" iconCls="icon-ok" style="width:60px;margin-right:20px;">确定</a>       
            <a class="mini-button" onclick="onCancel" iconCls="icon-close" style="width:60px;">取消</a>       
        </div>        
    </form>
	</fieldset>
    <script type="text/javascript">
        mini.parse();
		var judge=true;
		 var judge2=true;
		 var aab131 = mini.getbyName("aab131").getValue();
        var aab003 = mini.getbyName("aab003").getValue();
        if(aab131==" "){mini.getbyName("aab131").setValue("");}
        if(aab003==" "){mini.getbyName("aab003").setValue("");}
        var form = new mini.Form("form1");
		mini.getbyName("aab019").setValue("个体工商户");
		
         function SaveData() {
            var o = form.getData();            
            form.validate();
            if (form.isValid() == false) return;
            var json = mini.encode([o]);
            $.ajax({
                url: "/zyk/cs_ounit.do?method=savecs_ounit",
				type: 'post',
                data: { data: json},
                cache: false,
                success: function (text) {
                    CloseWindow("save");
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }

	
		
	
	
         function CloseWindow(action) {            
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();            
        }
        
        function onOk(e) {
        /*  checkSame();
         checkName();
       	if(judge&judge2){
          SaveData();
          mini.alert("修改成功！");
          window.close(); 
     	 }  */
     	 checkSame1();
     	 var name = mini.getbyName("aab004").getValue().trim();
     
     var id = mini.get("#id").getValue().trim();
      $.ajax({
           	 url: "/zyk/cs_ounit.do?method=getunitname",
           	 async: false,
             dataType : 'JSON',
	 		 data : {name:name},
             success: function(result) {
     	     if(result!=null)
     	     	{
			 		if(id==result.aab999 && name==result.aab004)
			 			{
					 		SaveData();
					 		mini.alert("修改成功！");
						}
					if(id!=result.aab999 && name==result.aab004)
						{	
							mini.alert("单位名称重复，请重新输入");
						}
				}else
					{
						SaveData();
					}
        }
        });
        
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
       
       
        function onCancel(e) {
            CloseWindow("cancel");
        }


	 function onDeptChanged(e) {
            var deptCombo = mini.getbyName("dept_id");
            var positionCombo = mini.getbyName("position");
            var dept_id = deptCombo.getValue();

            positionCombo.load("../data/AjaxService.jsp?method=GetPositionsByDepartmenId&id=" + dept_id);
            positionCombo.setValue("");
        }

	////////////
	 function onNumber(e){
		var zjlx=mini.get("#type").getValue();
		if(zjlx == '01'){
			if(e.isValid){
			
				if(isNumber(e.value) == false){
					e.errorText = "身份证输入不合法";
					e.isValid = false;
					
					//mini.alert(e.errorText);
				}
			}
		}
	}	
	
	function isNumber(v){
        var tel = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
        var flag = true;
        if(!tel.test(v)){
            flag = false;
        }else{
            var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            var nTemp = 0, i;
            var temp = v.substring(0,17);
            for (i = 0; i < temp.length; i++) {
                 nTemp += temp.substr(i, 1) * arrInt[i];
                }
                temp += arrCh[nTemp % 11];
            if(temp != v) {
               flag = false;
            }
        }
          return flag;
    }

	 function SetData(data) {
            if (data.action == "edit") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
               
                $.ajax({
                    url: "/zyk/cs_ounit.do?method=getcs_ounitdata&id=" + data.id,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                         onDeptChanged();
                        mini.getbyName("aab073").setValue(o.aab073);
                        onDeptChanged2();
                        mini.getbyName("aab074").setValue(o.aab074);
                        onDeptChanged3();
                        mini.getbyName("aab081").setValue(o.aab081);
                        onDeptChanged4();
                        mini.getbyName("aab082").setValue(o.aab082);
                        //onDeptChanged();
                        //mini.getbyName("position").setValue(o.position);
                    }
                });
                }
                }
            
function checkName(){
     var name = mini.getbyName("aab004").getValue().trim();
     
     var id = mini.get("#id").getValue().trim();
     
     
	 $.ajax({
           	 url: "/zyk/cs_ounit.do?method=getunitname",
           	 async: false,
             dataType : 'JSON',
	 		 data : {name:name},
             success: function(result) {
                 
			//已经存在该名字提示用户
			/* if(id !=result.aab999){
				if( name==result.aab004){
					
						mini.alert("该单位已注册，请核实");
						mini.get("#unit_name").setValue();
						judge=false;
					}
				}else{
					judge=true;
				} */
				if(result!=null){
					
					 if(id==result.aab999 && name==result.aab004){
					 		
					 		flag=true;
						}
						
					if(id!=result.aab999 && name==result.aab004)
						 {	
							mini.alert("该单位已注册，请重新输入");
							flag=false;
						}
					}else{
						flag=true; 
					}
				
				
				
				}
				
               });
               }
               
    function checkSame()
{
    var credit_id = mini.get("#credit_id").getValue();
    var organization_id = mini.get("#organization_id").getValue();
    if(credit_id!="" && organization_id!="" ){
       mini.alert("信用编码和组织机构代码不能同时输入！");
       judge2=false;
   }
   else if(credit_id==""&&organization_id==""){
       mini.alert("信用编码和组织机构代码不能同时为空！");
       judge2=false;
   }else{
   	 judge2=true;
   }
}  

    function checkSame1()
{
    var credit_id = mini.get("#credit_id").getValue();
    var organization_id = mini.get("#organization_id").getValue();
    if(credit_id!="" && organization_id!="" ){
    	 mini.get("#organization_id").setValue();
       mini.alert("信用编码和组织机构代码不能同时输入！");
     
     //  judge2=false;
   }
   else{
   	 judge2=true;
   }
} 
  
function onDrawDate(e) {
            var date = e.date;
            var d = new Date();

            if (date.getTime() > d.getTime()) {
                e.allowSelect = false;
            }
        }
        
function onDeptChanged(e) {
    var aab078 = mini.getbyName("aab078").getValue();
    var aab073 = mini.getbyName("aab073");
    var aab074 = mini.getbyName("aab074"); 
    aab073.load("${pageContext.request.contextPath }/cs_ounit.do?method=getselect1&dept_id="+aab078);
    aab073.setValue("");
    aab074.setValue("");
   } 
    function onDeptChanged2(e) {
    var aab073 = mini.getbyName("aab073").getValue();
    var aab074 = mini.getbyName("aab074");
    var url= "${pageContext.request.contextPath }/cs_ounit.do?method=getselect2&dept_id="+aab073;
    aab074.load(url);
    aab074.setValue("");
   }
   function onDeptChanged3(e) {
    var aab077 = mini.getbyName("aab077").getValue();
    var aab081 = mini.getbyName("aab081");
    var aab082 = mini.getbyName("aab082");
    var url= "${pageContext.request.contextPath }/cs_ounit.do?method=getselect1&dept_id="+aab077;
    aab081.load(url);
    aab081.setValue("");
    aab082.setValue("");
   } 
   function onDeptChanged4(e) {
    var aab081 = mini.getbyName("aab081").getValue();
    var aab082 = mini.getbyName("aab082");
    var url= "${pageContext.request.contextPath }/cs_ounit.do?method=getselect2&dept_id="+aab081;
    aab082.load(url);
    aab082.setValue("");
   }
    </script>
</body>
</html>
